﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class RoleDAO
    {
        public List<aspnet_Role> LayDanhSach()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Roles
                       select c;
            return list.ToList();
        }

        public aspnet_Role LayTheoId(Guid Id)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Roles
                       where c.RoleId == Id
                       select c;
            return list.Single();

        }


        public void Them(aspnet_Role temp)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.aspnet_Roles.InsertOnSubmit(temp);
            EFashionDB.SubmitChanges();

        }

        public void Xoa(aspnet_Role temp)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Roles
                       where c.RoleId == temp.RoleId
                       select c;
            aspnet_Role Result = list.Single();
            EFashionDB.aspnet_Roles.DeleteOnSubmit(Result);
            EFashionDB.SubmitChanges();


        }

        public void CapNhat(aspnet_Role temp)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Roles
                       where c.RoleId == temp.RoleId
                       select c;

            foreach (aspnet_Role u in EFashionDB.aspnet_Roles)
            {
                u.RoleName = temp.RoleName;
                u.Description = temp.Description;
                u.LoweredRoleName = temp.LoweredRoleName;
            }

            EFashionDB.SubmitChanges();

        }

        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/
        public aspnet_Role LayRoleTheoLoweredRoleName(String lrn)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            aspnet_Role select = EFashionDB.aspnet_Roles.Single(c => c.LoweredRoleName == lrn);
            return select;
        }

        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/


    }
}
